<template>
	<view class="p-t-20">
		<view class="font-32 font-weight m-l-30">更换绑定手机号</view>
		<view class="font-24 grey m-l-30 m-t-10">更换手机号后，旧手机号将不可使用，请谨慎操作</view>

		<view class="modelBox flex" style="border-radius: 10rpx;">
			<view class="m-r-60">+86</view>
			<input type="tel" v-model="mobile" style="width: 100%;" placeholder="请输入新手机号"
				placeholder-class="font-28 grey" maxlength="11">
		</view>
		<view class="modelBox flex_b" style="border-radius: 10rpx;">
			<input type="text" v-model="captcha" placeholder="请输入验证码"
				placeholder-class="font-28 grey">
			<view class="w-160 f-t" @click="getCode">{{tips||'获取验证码'}}</view>
		</view>
		<uv-code :seconds="seconds" @end="end" @start="start" ref="code" @change="codeChange"></uv-code>
		<view class="bomPosition">
			<button type="primary" @click="preserve">提交</button>
		</view>
		<uv-toast ref="toast"></uv-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tips: '',
				seconds: 60,
				mobile: '',
				captcha: ''
			};
		},
		methods: {
			preserve() {
				this.$api.sendRequest({
					url: '/api/User/changemobile',
					data: {
						mobile: this.mobile,
						captcha: this.captcha,
					},
					success: res => {
						this.$refs.toast.show({
							type: 'default',
							message: res.msg,
							duration: 1500
						})
						if (res.code == 1) {
							setTimeout(() => {
								uni.navigateBack()
							}, 1500)
						} else {

						}

					}
				})
			},
			codeChange(text) {
				this.tips = text
			},
			getCode() {
				// 模拟向后端请求验证码
				uni.showLoading({
					title: '正在获取验证码'
				})
				setTimeout(() => {
					uni.hideLoading();
					// 这里此提示会被this.start()方法中的提示覆盖
					// uni.$uv.toast('验证码已发送');
					// 通知验证码组件内部开始倒计时
					this.$refs.code.start();
				}, 2000);

			},
			end() {
				// uni.$uv.toast('倒计时结束');
			},
			start() {
				// uni.$uv.toast('倒计时开始');
			},
			causeFn() {

			}
		}
	}
</script>

<style lang="scss">

</style>
